<?php
/*
Plugin Name: WP-Book Library
Version: 1.0-alpha
Plugin URI: http://myanmapress.com
Description: Manage Book library.
Author: Sithu Thwin
Author URI: http://myanmapress.com
 */
 if(defined('WPBL_VERSION')) return;
define('WPBL_VERSION', '1.0-alpha');
define('WPBL_PLUGIN_PATH', dirname(__FILE__));
define('WPBL_PLUGIN_FOLDER', basename(WPBL_PLUGIN_PATH));

if(defined('WP_ADMIN') && defined('FORCE_SSL_ADMIN') && FORCE_SSL_ADMIN){
    define('WPBL_PLUGIN_URL', rtrim(str_replace('http://','https://',get_option('siteurl')),'/') . '/'. PLUGINDIR . '/' . basename(dirname(__FILE__)) );
}else{
    define('WPBL_PLUGIN_URL', rtrim(get_option('siteurl'),'/') . '/'. PLUGINDIR . '/' . basename(dirname(__FILE__)) );
}
include_once (WPBL_PLUGIN_PATH.'/register_types.php');
include (WPBL_PLUGIN_PATH.'/library.php');
include (WPBL_PLUGIN_PATH.'/widgets.php');
include (WPBL_PLUGIN_PATH.'/meta_boxes.php');
include (WPBL_PLUGIN_PATH.'/meta-box.php');
include (WPBL_PLUGIN_PATH.'/aviablity.php');
include (WPBL_PLUGIN_PATH.'/admin_widget.php');
$CPT_URL = cpt_check_return( 'add' );
// create custom plugin settings menu
add_action('admin_menu', 'cpt_plugin_menu');
//call delete post function
add_action( 'admin_init', 'cpt_delete_post_type' );
//call register settings function
add_action( 'admin_init', 'cpt_register_settings' );

add_action('admin_menu', 'addWPBLSubmenu');
add_action( 'init', 'create_post_type', 0 );
add_action( 'init', 'create_taxonomies_type', 0 );
function addWPBLSubmenu(){
}



function get_disp_boolean($booText) {
	If ($booText == '0') {
		return false;
	}Else{
		return true;
	}
}

function disp_boolean($booText) {
	If ($booText == '0') {
		return 'false';
	}Else{
		return 'true';
	}
}
function cpt_plugin_menu() {

	add_menu_page('Add New Field', 'Add New Field', 10, 'cpt_main_menu', 'cpt_add_new');
	//create submenu items
	add_submenu_page('cpt_main_menu', 'Add New', 'Add New', 'administrator', 'cpt_sub_add_new', 'cpt_add_new');
	add_submenu_page('cpt_main_menu', 'Manage Taxonomies', 'Manage Taxonomies', 'administrator', 'cpt_sub_manage_taxonomies', 'cpt_manage_taxonomies');

}

//temp fix, should do: http://planetozh.com/blog/2008/04/how-to-load-javascript-with-your-wordpress-plugin/
//only load JS if on a CPT page
If ( strpos($_SERVER['REQUEST_URI'], 'cpt')>0 ) {
	add_action( 'admin_head', 'cpt_wp_add_styles' );
}
// Add JS Scripts
function cpt_wp_add_styles() {
	?>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js">
        </script>
        <script type="text/javascript" >
        jQuery(document).ready(function()
        {
        jQuery(".comment_button").click(function(){

        var element = jQuery(this);
        var I = element.attr("id");

        jQuery("#slidepanel"+I).slideToggle(300);
        jQuery(this).toggleClass("active");

        return false;
        });
        });
        </script>
    <?php
}

//delete custom post type or custom taxonomy
function cpt_delete_post_type() {
	global $CPT_URL;
	//check if we are deleting a custom taxonomy
	If(isset($_GET['deltax'])) {
		check_admin_referer('cpt_delete_tax');

		$delType = intval($_GET['deltax']);
		$cpt_taxonomies = get_option('cpt_custom_tax_types');

		unset($cpt_taxonomies[$delType]);

		$cpt_taxonomies = array_values($cpt_taxonomies);

		update_option('cpt_custom_tax_types', $cpt_taxonomies);

		If (isset($_GET['return'])) {
			$RETURN_URL = cpt_check_return(esc_attr($_GET['return']));
		}Else{
			$RETURN_URL = $CPT_URL;
		}

		wp_redirect($RETURN_URL .'&cpt_msg=del');
	}

}

function cpt_register_settings() {
	global $cpt_error, $CPT_URL;

	If (isset($_POST['cpt_edit_tax'])) {
		//edit a custom taxonomy
		check_admin_referer('cpt_add_custom_taxonomy');

		//custom taxonomy to edit
		$cpt_edit = intval($_POST['cpt_edit_tax']);

		//edit the custom taxonomy
		$cpt_form_fields = $_POST['cpt_custom_tax'];

		//add label values to array
		array_push($cpt_form_fields, $_POST['cpt_tax_labels']);

		//add attached post type values to array
		array_push($cpt_form_fields, $_POST['cpt_post_types']);

		//load custom posts saved in WP
		$cpt_options = get_option('cpt_custom_tax_types');

		If (is_array($cpt_options)) {

			unset($cpt_options[$cpt_edit]);

			//insert new custom post type into the array
			array_push($cpt_options, $cpt_form_fields);

			$cpt_options = array_values($cpt_options);

			//save custom post types
			update_option('cpt_custom_tax_types', $cpt_options);

			If (isset($_GET['return'])) {
				$RETURN_URL = cpt_check_return(esc_attr($_GET['return']));
			}Else{
				$RETURN_URL = $CPT_URL;
			}

			wp_redirect($RETURN_URL);

		}

	}ElseIf(isset($_POST['cpt_add_tax'])) {
		//create new custom taxonomy
		check_admin_referer('cpt_add_custom_taxonomy');

		//retrieve new custom taxonomy values
		$cpt_form_fields = $_POST['cpt_custom_tax'];

		//verify required fields are filled out
		If (empty($cpt_form_fields["name"])) {
			If (isset($_GET['return'])) {
				$RETURN_URL = cpt_check_return(esc_attr($_GET['return']));
			}Else{
				$RETURN_URL = $CPT_URL;
			}

			wp_redirect($RETURN_URL .'&cpt_error=2');
			exit();
		}elseif ( empty( $_POST['cpt_post_types'] ) ) {
			If (isset($_GET['return'])) {
				$RETURN_URL = cpt_check_return(esc_attr($_GET['return']));
			}Else{
				$RETURN_URL = $CPT_URL;
			}

			wp_redirect($RETURN_URL .'&cpt_error=3');
			exit();
		}

		//add label values to array
		array_push($cpt_form_fields, $_POST['cpt_tax_labels']);

		//add attached post type values to array
		array_push($cpt_form_fields, $_POST['cpt_post_types']);

		//load custom taxonomies saved in WP
		$cpt_options = get_option('cpt_custom_tax_types');

		//check if option exists, if not create an array for it
		If (!is_array($cpt_options)) {
			$cpt_options = array();
		}

		//insert new custom taxonomy into the array
		array_push($cpt_options, $cpt_form_fields);

		//save new custom taxonomy array in the CPT option
		update_option('cpt_custom_tax_types', $cpt_options);

		If (isset($_GET['return'])) {
			$RETURN_URL = cpt_check_return(esc_attr($_GET['return']));
		}Else{
			$RETURN_URL = $CPT_URL;
		}

		wp_redirect($RETURN_URL .'&cpt_msg=2');

	}
}

//manage custom taxonomies page
function cpt_manage_taxonomies() {
	global $CPT_URL;

	$MANAGE_URL = cpt_check_return( 'add' );

?>
<div class="wrap">
<?php
//check for success/error messages
If (isset($_GET['cpt_msg']) && $_GET['cpt_msg']=='del') { ?>
    <div id="message" class="updated">
    	<?php _e('Custom taxonomy deleted successfully', 'cpt-plugin'); ?>
    </div>
    <?php
}
?>
<?php screen_icon( 'plugins' ); ?>
<h2><?php _e('Manage Custom Taxonomies', 'cpt-plugin') ?></h2>
<p><?php _e('Deleting custom taxonomies does <strong>NOT</strong> delete any content added to those taxonomies.  You can easily recreate your taxonomies and the content will still exist.', 'cpt-plugin') ?></p>
<?php
	$cpt_tax_types = get_option('cpt_custom_tax_types');

	If (is_array($cpt_tax_types)) {
		?>
        <table width="100%" class="widefat">
            <thead>
                <tr>
            	<th><?php _e('Action', 'cpt-plugin');?></th>
            	<th><?php _e('Name', 'cpt-plugin');?></th>
                <th><?php _e('Label', 'cpt-plugin');?></th>
                <th><?php _e('Singular Label', 'cpt-plugin');?></th>
                <th><?php _e('Attached Post Types', 'cpt-plugin');?></th>
                <th><?php _e('Hierarchical', 'cpt-plugin');?></th>
                <th><?php _e('Show UI', 'cpt-plugin');?></th>
                <th><?php _e('Rewrite', 'cpt-plugin');?></th>
                <th><?php _e('Rewrite Slug', 'cpt-plugin');?></th>
                </tr>
            </thead>
            <tfoot>
                <tr>
            	<th><?php _e('Action', 'cpt-plugin');?></th>
            	<th><?php _e('Name', 'cpt-plugin');?></th>
                <th><?php _e('Label', 'cpt-plugin');?></th>
                <th><?php _e('Singular Label', 'cpt-plugin');?></th>
                <th><?php _e('Attached Post Types', 'cpt-plugin');?></th>
                <th><?php _e('Hierarchical', 'cpt-plugin');?></th>
                <th><?php _e('Show UI', 'cpt-plugin');?></th>
                <th><?php _e('Rewrite', 'cpt-plugin');?></th>
                <th><?php _e('Rewrite Slug', 'cpt-plugin');?></th>
                </tr>
            </tfoot>
        <?php
		$thecounter=0;
		foreach ($cpt_tax_types as $cpt_tax_type) {

			$del_url = cpt_check_return( 'cpt' ) .'&deltax=' .$thecounter .'&return=tax';
			$del_url = ( function_exists('wp_nonce_url') ) ? wp_nonce_url($del_url, 'cpt_delete_tax') : $del_url;

			$edit_url = $MANAGE_URL .'&edittax=' .$thecounter .'&return=tax';
			$edit_url = ( function_exists('wp_nonce_url') ) ? wp_nonce_url($edit_url, 'cpt_edit_tax') : $edit_url;

			$rewrite_slug = ( $cpt_tax_type["rewrite_slug"] ) ? $cpt_tax_type["rewrite_slug"] : $cpt_tax_type["name"];
		?>
        	<tr>
            	<td valign="top"><a href="<?php echo $del_url; ?>">Delete</a> / <a href="<?php echo $edit_url; ?>">Edit</a> / <a href="#" class="comment_button" id="<?php echo $thecounter; ?>">Get Code</a></td>
            	<td valign="top"><?php echo stripslashes($cpt_tax_type["name"]); ?></td>
                <td valign="top"><?php echo stripslashes($cpt_tax_type["label"]); ?></td>
                <td valign="top"><?php echo stripslashes($cpt_tax_type["singular_label"]); ?></td>
                <td valign="top">
				<?php
				if ( isset( $cpt_tax_type["cpt_name"] ) ) {
					echo stripslashes($cpt_tax_type["cpt_name"]);
				}elseif ( is_array( $cpt_tax_type[1] ) ) {
					foreach ($cpt_tax_type[1] as $cpt_post_types) {
						echo $cpt_post_types .'<br />';
					}
				}
				?>
                </td>
                <td valign="top"><?php echo disp_boolean($cpt_tax_type["hierarchical"]); ?></td>
                <td valign="top"><?php echo disp_boolean($cpt_tax_type["show_ui"]); ?></td>
                <td valign="top"><?php echo disp_boolean($cpt_tax_type["rewrite"]); ?></td>
                <td valign="top"><?php echo $rewrite_slug; ?></td>
            </tr>
        	<tr>
            	<td colspan="10">
                    <div style="display:none;" id="slidepanel<?php echo $thecounter; ?>">
                        <?php
                        //display register_taxonomy code
                        $cpt_tax_types = get_option('cpt_custom_tax_types');
                        $custom_tax = '';

                        //check if option value is an Array before proceeding
                        If (is_array($cpt_tax_types)) {
                            //foreach ($cpt_tax_types as $cpt_tax_type) {

                                If (!$cpt_tax_type["label"]) {
                                    $cpt_label = esc_html($cpt_tax_type["name"]);
                                }Else{
                                    $cpt_label = esc_html($cpt_tax_type["label"]);
                                }

                                //check if singular label was filled out
                                If (!$cpt_tax_type["singular_label"]) {
                                    $cpt_singular_label = esc_html($cpt_tax_type["name"]);
                                }Else{
                                    $cpt_singular_label = esc_html($cpt_tax_type["singular_label"]);
                                }

				$cpt_post_types = ( !$cpt_tax_type[1] ) ? $cpt_tax_type["cpt_name"] : var_export( $cpt_tax_type[1], true );

                                //register our custom taxonomies
                                $custom_tax = 'register_taxonomy(\'' .$cpt_tax_type["name"]. '\',';
                                $custom_tax .= $cpt_post_types .',';
                                $custom_tax .= 'array( \'hierarchical\' => '.disp_boolean($cpt_tax_type["hierarchical"]).', ';
                                $custom_tax .= 	'\'label\' => \''.$cpt_label.'\',';
                                $custom_tax .= 	'\'show_ui\' => '.disp_boolean($cpt_tax_type["show_ui"]).',';
                                $custom_tax .= 	'\'query_var\' => '. disp_boolean($cpt_tax_type["query_var"]).',';
				$custom_tax .= 	'\'rewrite\' => array(\'slug\' => \'' .$cpt_tax_type["rewrite_slug"]. '\'),';
                                $custom_tax .= 	'\'singular_label\' => \''.$cpt_singular_label.'\'';
                                $custom_tax .= ') );';

				echo '<br>';
				echo _e('Place the below code in your themes functions.php file to manually create this custom taxonomy','cpt-plugin').'<br>';
				echo _e('This is a <strong>BETA</strong> feature.  Please <a href="http://webdevstudios.com/support/forum/custom-post-type-ui/">report bugs</a>.','cpt-plugin').'<br>';
                                echo '<textarea rows="5" cols="100">' .$custom_tax .'</textarea>';

                            //}
                        }
                        ?>
                    </div>
				</td>
            </tr>
		<?php
		$thecounter++;
		}
		?></table>
		</div>
		<?php
		//load footer
		cpt_footer();
	}
}

//add new custom post type / taxonomy page
function cpt_add_new() {
	global $cpt_error, $CPT_URL;

	If (isset($_GET['return'])) {
		$RETURN_URL = 'action="' .cpt_check_return(esc_attr($_GET['return'])). '"';
	}Else{
		$RETURN_URL = '';
	}

If (isset($_GET['edittax']) && !isset($_GET['cpt_edit'])) {
	check_admin_referer('cpt_edit_tax');

	//get post type to edit
	$editTax = intval($_GET['edittax']);

	//load custom posts saved in WP
	$cpt_options = get_option('cpt_custom_tax_types');

	//load custom post type values to edit
	$cpt_tax_name = $cpt_options[$editTax]["name"];
	$cpt_tax_label = $cpt_options[$editTax]["label"];
	$cpt_singular_label = $cpt_options[$editTax]["singular_label"];
	$cpt_tax_object_type = ( isset( $cpt_options[$editTax]["cpt_name"] ) ) ? $cpt_options[$editTax]["cpt_name"] : null;
	$cpt_tax_hierarchical = $cpt_options[$editTax]["hierarchical"];
	$cpt_tax_showui = $cpt_options[$editTax]["show_ui"];
	$cpt_tax_query_var = $cpt_options[$editTax]["query_var"];
	$cpt_tax_rewrite = $cpt_options[$editTax]["rewrite"];
	$cpt_tax_rewrite_slug = $cpt_options[$editTax]["rewrite_slug"];
	$cpt_tax_labels = $cpt_options[$editTax][0];
	$cpt_post_types = $cpt_options[$editTax][1];

	$cpt_tax_submit_name = 'Save Custom Taxonomy';
}Else{
	$cpt_tax_submit_name = 'Create Custom Taxonomy';
}

//flush rewrite rules
flush_rewrite_rules();

?><div class="wrap"><?php
//check for success/error messages
If (isset($_GET['cpt_msg']) && $_GET['cpt_msg']==2) { ?>
    <div id="message" class="updated">
    	<?php _e('Custom taxonomy created successfully.  You may need to refresh to view the new taxonomy.  <a href="' .cpt_check_return( 'tax' ) .'">Manage custom taxonomies</a>', 'cpt-plugin'); ?>
    </div>
    <?php
}else{
If (isset($_GET['cpt_error']) && $_GET['cpt_error']==2) { ?>
		<div class="error">
			<?php _e('Taxonomy name is a required field.', 'cpt-plugin'); ?>
		</div>
	<?php }ElseIf (isset($_GET['cpt_error']) && $_GET['cpt_error']==3) { ?>
		<div class="error">
			<?php _e('You must assign your custom taxonomy to at least one post type.', 'cpt-plugin'); ?>
		</div>
	<?php }
}
?>
<?php screen_icon( 'plugins' ); ?>
<?php If ( isset( $_GET['edittype'] ) || isset( $_GET['edittax'] ) ) { ?>
    <h2><?php _e('Edit Custom Taxonomy', 'cpt-plugin') ?> &middot; <a href="<?php echo cpt_check_return( 'add' ); ?>"><?php _e('Reset', 'cpt-plugin');?></a></h2>
<?php }Else{ ?>
    <h2><?php _e('Create New Custom Taxonomy', 'cpt-plugin') ?> &middot; <a href="<?php echo cpt_check_return( 'add' ); ?>"><?php _e('Reset', 'cpt-plugin');?></a></h2>
<?php } ?>
<table border="0" cellspacing="10" class="widefat">
	<tr>
    	 <td width="100%" valign="top">
        	<?php
			//debug area
			$cpt_options = get_option('cpt_custom_tax_types');
			?>
        	<p><?php _e('If you are unfamiliar with the options below only fill out the <strong>Taxonomy Name</strong> and <strong>Post Type Name</strong> fields.  The other settings are set to the most common defaults for custom taxonomies.', 'cpt-plugin');?></p>
            <form method="post" <?php echo $RETURN_URL; ?>>
                <?php if ( function_exists('wp_nonce_field') )
                    wp_nonce_field('cpt_add_custom_taxonomy'); ?>
                <?php If (isset($_GET['edittax'])) { ?>
                <input type="hidden" name="cpt_edit_tax" value="<?php echo $editTax; ?>" />
                <?php } ?>
                <table class="form-table">
                    <tr valign="top">
                    <th scope="row"><?php _e('Taxonomy Name', 'cpt-plugin') ?> <span style="color:red;">*</span></th>
                    <td><input type="text" name="cpt_custom_tax[name]" tabindex="21" value="<?php If (isset($cpt_tax_name)) { echo esc_attr($cpt_tax_name); } ?>" /> <a href="#" title="The taxonomy name.  Used to retrieve custom taxonomy content.  Should be short and sweet" style="cursor: help;">?</a> (e.g. actors)</td>
                    </tr>

                   <tr valign="top">
                    <th scope="row"><?php _e('Label', 'cpt-plugin') ?></th>
                    <td><input type="text" name="cpt_custom_tax[label]" tabindex="22" value="<?php If (isset($cpt_tax_label)) { echo esc_attr($cpt_tax_label); } ?>" /> <a href="#" title="Taxonomy label.  Used in the admin menu for displaying custom taxonomy." style="cursor: help;">?</a> (e.g. Actors)</td>
                    </tr>

                   <tr valign="top">
                    <th scope="row"><?php _e('Singular Label', 'cpt-plugin') ?></th>
                    <td><input type="text" name="cpt_custom_tax[singular_label]" tabindex="23" value="<?php If (isset($cpt_singular_label)) { echo esc_attr($cpt_singular_label); } ?>" /> <a href="#" title="Taxonomy Singular label.  Used in WordPress when a singular label is needed." style="cursor: help;">?</a> (e.g. Actor)</td>
                    </tr>

                   <tr valign="top">
                    <th scope="row"><?php _e('Attach to Post Type', 'cpt-plugin') ?> <span style="color:red;">*</span></th>
                    <td>
                    <?php if ( isset( $cpt_tax_object_type ) ) { ?>
                    	<strong>This is the old method.  Delete the post type from the textbox and check which post type to attach this taxonomy to</strong>
                    	<input type="text" name="cpt_custom_tax[cpt_name]" tabindex="24" value="<?php If (isset($cpt_tax_object_type)) { echo esc_attr($cpt_tax_object_type); } ?>" /> <a href="#" title="What object to attach the custom taxonomy to.  Can be post, page, or link by default.  Can also be any custom post type name." style="cursor: help;">?</a> (e.g. movies)
                    <?php } ?>
                    <?php
                    $args=array(
                      'public'   => true
                    );
                    $output = 'objects'; // or objects
                    $post_types=get_post_types($args,$output);
					foreach ($post_types  as $post_type ) {
						if ( $post_type->name != 'attachment' ) {
						?>
                        <input type="checkbox" name="cpt_post_types[]" tabindex="20" value="<?php echo $post_type->name; ?>" <?php If (isset($cpt_post_types) && is_array($cpt_post_types)) { If (in_array($post_type->name, $cpt_post_types)) { echo 'checked="checked"'; } } ?> />&nbsp;<?php echo $post_type->label; ?><br />
                        <?php
						}
					}
					?>
                    </td>
                    </tr>

            		<tr valign="top">
                        <td colspan="2">
                            <p align="center">
                            <?php echo '<a href="#" class="comment_button" id="3">' . __('Advanced Label Options', 'cpt-plugin') . '</a>'; ?> &middot;
                            <?php echo '<a href="#" class="comment_button" id="4">' . __('Advanced Options', 'cpt-plugin') . '</a>'; ?>
                            </p>
                        </td>
                    </tr>

				</table>

                <div style="display:none;" id="slidepanel3">
                <p><?php _e('Below are the advanced label options for custom taxonomies.  If you are unfamiliar with these labels the plugin will automatically create labels based off of your custom taxonomy name', 'cpt-plugin'); ?></p>
                <table class="form-table">
                    <tr valign="top">
                    <th scope="row"><?php _e('Search Items', 'cpt-plugin') ?></th>
                    <td><input type="text" name="cpt_tax_labels[search_items]" tabindex="2" value="<?php If (isset($cpt_tax_labels["search_items"])) { echo esc_attr($cpt_tax_labels["search_items"]); } ?>" /> <a href="#" title="Custom taxonomy label.  Used in the admin menu for displaying taxonomies." style="cursor: help;">?</a> (e.g. Search Actors)</td>
                    </tr>

                    <tr valign="top">
                    <th scope="row"><?php _e('Popular Items', 'cpt-plugin') ?></th>
                    <td><input type="text" name="cpt_tax_labels[popular_items]" tabindex="2" value="<?php If (isset($cpt_tax_labels["popular_items"])) { echo esc_attr($cpt_tax_labels["popular_items"]); } ?>" /> <a href="#" title="Custom taxonomy label.  Used in the admin menu for displaying taxonomies." style="cursor: help;">?</a> (e.g. Popular Actors)</td>
                    </tr>

                    <tr valign="top">
                    <th scope="row"><?php _e('All Items', 'cpt-plugin') ?></th>
                    <td><input type="text" name="cpt_tax_labels[all_items]" tabindex="2" value="<?php If (isset($cpt_tax_labels["all_items"])) { echo esc_attr($cpt_tax_labels["all_items"]); } ?>" /> <a href="#" title="Custom taxonomy label.  Used in the admin menu for displaying taxonomies." style="cursor: help;">?</a> (e.g. All Actors)</td>
                    </tr>

                    <tr valign="top">
                    <th scope="row"><?php _e('Parent Item', 'cpt-plugin') ?></th>
                    <td><input type="text" name="cpt_tax_labels[parent_item]" tabindex="2" value="<?php If (isset($cpt_tax_labels["parent_item"])) { echo esc_attr($cpt_tax_labels["parent_item"]); } ?>" /> <a href="#" title="Custom taxonomy label.  Used in the admin menu for displaying taxonomies." style="cursor: help;">?</a> (e.g. Parent Actor)</td>
                    </tr>

                    <tr valign="top">
                    <th scope="row"><?php _e('Parent Item Colon', 'cpt-plugin') ?></th>
                    <td><input type="text" name="cpt_tax_labels[parent_item_colon]" tabindex="2" value="<?php If (isset($cpt_tax_labels["parent_item_colon"])) { echo esc_attr($cpt_tax_labels["parent_item_colon"]); } ?>" /> <a href="#" title="Custom taxonomy label.  Used in the admin menu for displaying taxonomies." style="cursor: help;">?</a> (e.g. Parent Actor:)</td>
                    </tr>

                    <tr valign="top">
                    <th scope="row"><?php _e('Edit Item', 'cpt-plugin') ?></th>
                    <td><input type="text" name="cpt_tax_labels[edit_item]" tabindex="2" value="<?php If (isset($cpt_tax_labels["edit_item"])) { echo esc_attr($cpt_tax_labels["edit_item"]); } ?>" /> <a href="#" title="Custom taxonomy label.  Used in the admin menu for displaying taxonomies." style="cursor: help;">?</a> (e.g. Edit Actor)</td>
                    </tr>

                    <tr valign="top">
                    <th scope="row"><?php _e('Update Item', 'cpt-plugin') ?></th>
                    <td><input type="text" name="cpt_tax_labels[update_item]" tabindex="2" value="<?php If (isset($cpt_tax_labels["update_item"])) { echo esc_attr($cpt_tax_labels["update_item"]); } ?>" /> <a href="#" title="Custom taxonomy label.  Used in the admin menu for displaying taxonomies." style="cursor: help;">?</a> (e.g. Update Actor)</td>
                    </tr>

                    <tr valign="top">
                    <th scope="row"><?php _e('Add New Item', 'cpt-plugin') ?></th>
                    <td><input type="text" name="cpt_tax_labels[add_new_item]" tabindex="2" value="<?php If (isset($cpt_tax_labels["add_new_item"])) { echo esc_attr($cpt_tax_labels["add_new_item"]); } ?>" /> <a href="#" title="Custom taxonomy label.  Used in the admin menu for displaying taxonomies." style="cursor: help;">?</a> (e.g. Add New Actor)</td>
                    </tr>

                    <tr valign="top">
                    <th scope="row"><?php _e('New Item Name', 'cpt-plugin') ?></th>
                    <td><input type="text" name="cpt_tax_labels[new_item_name]" tabindex="2" value="<?php If (isset($cpt_tax_labels["new_item_name"])) { echo esc_attr($cpt_tax_labels["new_item_name"]); } ?>" /> <a href="#" title="Custom taxonomy label.  Used in the admin menu for displaying taxonomies." style="cursor: help;">?</a> (e.g. New Actor Name)</td>
                    </tr>

                    <tr valign="top">
                    <th scope="row"><?php _e('Separate Items with Commas', 'cpt-plugin') ?></th>
                    <td><input type="text" name="cpt_tax_labels[separate_items_with_commas]" tabindex="2" value="<?php If (isset($cpt_tax_labels["separate_items_with_commas"])) { echo esc_attr($cpt_tax_labels["separate_items_with_commas"]); } ?>" /> <a href="#" title="Custom taxonomy label.  Used in the admin menu for displaying taxonomies." style="cursor: help;">?</a> (e.g. Separate actors with commas)</td>
                    </tr>

                    <tr valign="top">
                    <th scope="row"><?php _e('Add or Remove Items', 'cpt-plugin') ?></th>
                    <td><input type="text" name="cpt_tax_labels[add_or_remove_items]" tabindex="2" value="<?php If (isset($cpt_tax_labels["add_or_remove_items"])) { echo esc_attr($cpt_tax_labels["add_or_remove_items"]); } ?>" /> <a href="#" title="Custom taxonomy label.  Used in the admin menu for displaying taxonomies." style="cursor: help;">?</a> (e.g. Add or remove actors)</td>
                    </tr>

                    <tr valign="top">
                    <th scope="row"><?php _e('Choose From Most Used', 'cpt-plugin') ?></th>
                    <td><input type="text" name="cpt_tax_labels[choose_from_most_used]" tabindex="2" value="<?php If (isset($cpt_tax_labels["choose_from_most_used"])) { echo esc_attr($cpt_tax_labels["choose_from_most_used"]); } ?>" /> <a href="#" title="Custom taxonomy label.  Used in the admin menu for displaying taxonomies." style="cursor: help;">?</a> (e.g. Choose from the most used actors)</td>
                    </tr>
                </table>
                </div>

                <div style="display:none;" id="slidepanel4">
                <table class="form-table">
                    <tr valign="top">
                    <th scope="row"><?php _e('Hierarchical', 'cpt-plugin') ?></th>
                    <td>
                        <SELECT name="cpt_custom_tax[hierarchical]" tabindex="25">
                            <OPTION value="0" <?php If (isset($cpt_tax_hierarchical)) { If ($cpt_tax_hierarchical == 0) { echo 'selected="selected"'; } }Else{ echo 'selected="selected"'; } ?>>False</OPTION>
                            <OPTION value="1" <?php If (isset($cpt_tax_hierarchical)) { If ($cpt_tax_hierarchical == 1) { echo 'selected="selected"'; } } ?>>True</OPTION>
                        </SELECT> <a href="#" title="Whether the taxonomy is hierarchical" style="cursor: help;">?</a> (default: False)
                    </td>
                    </tr>

                    <tr valign="top">
                    <th scope="row"><?php _e('Show UI', 'cpt-plugin') ?></th>
                    <td>
                        <SELECT name="cpt_custom_tax[show_ui]" tabindex="26">
                            <OPTION value="0" <?php If (isset($cpt_tax_showui)) { If ($cpt_tax_showui == 0 && $cpt_tax_showui != '') { echo 'selected="selected"'; } } ?>>False</OPTION>
                            <OPTION value="1" <?php If (isset($cpt_tax_showui)) { If ($cpt_tax_showui == 1 || is_null($cpt_tax_showui)) { echo 'selected="selected"'; } }Else{ echo 'selected="selected"'; } ?>>True</OPTION>
                        </SELECT> <a href="#" title="Whether to generate a default UI for managing this custom taxonomy" style="cursor: help;">?</a> (default: True)
                    </td>
                    </tr>

                    <tr valign="top">
                    <th scope="row"><?php _e('Query Var', 'cpt-plugin') ?></th>
                    <td>
                        <SELECT name="cpt_custom_tax[query_var]" tabindex="27">
                            <OPTION value="0" <?php If (isset($cpt_tax_query_var)) { If ($cpt_tax_query_var == 0 && $cpt_tax_query_var != '') { echo 'selected="selected"'; } } ?>>False</OPTION>
                            <OPTION value="1" <?php If (isset($cpt_tax_query_var)) { If ($cpt_tax_query_var == 1 || is_null($cpt_tax_query_var)) { echo 'selected="selected"'; } }Else{ echo 'selected="selected"'; } ?>>True</OPTION>
                        </SELECT> <a href="#" title="" style="cursor: help;">?</a> (default: True)
                    </td>
                    </tr>

                    <tr valign="top">
                    <th scope="row"><?php _e('Rewrite', 'cpt-plugin') ?></th>
                    <td>
                        <SELECT name="cpt_custom_tax[rewrite]" tabindex="28">
                            <OPTION value="0" <?php If (isset($cpt_tax_rewrite)) { If ($cpt_tax_rewrite == 0 && $cpt_tax_rewrite != '') { echo 'selected="selected"'; } } ?>>False</OPTION>
                            <OPTION value="1" <?php If (isset($cpt_tax_rewrite)) { If ($cpt_tax_rewrite == 1 || is_null($cpt_tax_rewrite)) { echo 'selected="selected"'; } }Else{ echo 'selected="selected"'; } ?>>True</OPTION>
                        </SELECT> <a href="#" title="" style="cursor: help;">?</a> (default: True)
                    </td>
                    </tr>

                    <tr valign="top">
                    <th scope="row"><?php _e('Custom Rewrite Slug', 'cpt-plugin') ?></th>
                    <td><input type="text" name="cpt_custom_tax[rewrite_slug]" tabindex="9" value="<?php If (isset($cpt_tax_rewrite_slug)) { echo esc_attr($cpt_tax_rewrite_slug); } ?>" /> <a href="#" title="Custom Taxonomy Rewrite Slug" style="cursor: help;">?</a> (default: taxonomy name)</td>
                    </tr>

                </table>
                </div>

                <p class="submit">
                	<input type="submit" class="button-primary" tabindex="29" name="cpt_add_tax" value="<?php _e($cpt_tax_submit_name, 'cpt-plugin') ?>" />
                </p>
            </form>
        </td>
	</tr>
</table>
</div>
<?php
//load footer
cpt_footer();

}

function cpt_footer() {
	?>
    <hr />
	<p class="cp_about"><a target="_blank" href="http://webdevstudios.com/support/forum/custom-post-type-ui/">Custom Post Type UI</a> v<?php echo CPT_VERSION; ?> - <a href="http://webdevstudios.com/support/forum/custom-post-type-ui/" target="_blank">Please Report Bugs</a> &middot; Follow on Twitter: <a href="http://twitter.com/williamsba" target="_blank">Brad</a> &middot; <a href="http://twitter.com/pluginize" target="_blank">Pluginize</a> &middot; <a href="http://twitter.com/webdevstudios" target="_blank">WDS</a></p>
	<?php
}

function cpt_check_return($return) {
	global $CPT_URL;

	If($return=='cpt') {
		return ( isset( $_GET['return'] ) ) ? admin_url('admin.php?page=cpt_sub_manage_cpt&return='.$_GET['return']) : admin_url('admin.php?page=cpt_sub_manage_cpt');
	}Elseif($return=='tax'){
		return ( isset( $_GET['return'] ) ) ? admin_url('admin.php?page=cpt_sub_manage_taxonomies&return='.$_GET['return']) : admin_url('admin.php?page=cpt_sub_manage_taxonomies');
	}Elseif($return=='add') {
		return admin_url('admin.php?page=cpt_sub_add_new');
	}Else{
		return admin_url('admin.php?page=cpt_sub_add_new');
	}
}

function one_column_for_pages1( $columns ) {
$columns['library'] = 2;
return $columns;
}
add_filter( 'screen_layout_columns', 'one_column_for_pages1' );

function one_column_for_pages2() {
return 2;
}
add_filter( 'get_user_option_screen_layout_page', 'one_column_for_pages2' );
function remove_update(){
global $wpdb, $current_user;
get_currentuserinfo();
$user_id = $current_user->ID;
if ( !current_user_can( 'edit_users' ) ) {
  add_action( 'init', create_function( '$a', "remove_action( 'init', 'wp_version_check' );" ), 2 );
  add_filter( 'pre_option_update_core', create_function( '$a', "return null;" ) );
}
}
add_action('init','remove_update');
function remove_menus () {
global $menu;
remove_menu_page(‘edit.php’); // Posts
remove_menu_page(‘upload.php’); // Media
remove_menu_page(‘link-manager.php’); // Links
remove_menu_page(‘edit-comments.php’); // Comments
//remove_menu_page(‘edit.php?post_type=page’); // Pages
remove_menu_page(‘plugins.php’); // Plugins
remove_menu_page(‘themes.php’); // Appearance
remove_menu_page(‘users.php’); // Users
remove_menu_page(‘tools.php’); // Tools
remove_menu_page(‘options-general.php’); // Settings
}
//add_action('admin_menu', 'remove_menus');
?>